package com.pe.pgn.clubpgn.dao.impl;

import java.util.List;

import javax.sql.DataSource;

import org.hibernate.Criteria;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;

import com.pe.pgn.clubpgn.common.CLPConstantes;
import com.pe.pgn.clubpgn.dao.TipoDocumentoDao;
import com.pe.pgn.clubpgn.dao.hibernate.GenericDaoHibernate;
import com.pe.pgn.clubpgn.domain.ClpdArticulo;
import com.pe.pgn.clubpgn.domain.ClpdTipoDocumento;

public class TipoDocumentoDaoImpl extends GenericDaoHibernate<ClpdTipoDocumento, Long > 
implements TipoDocumentoDao{
	
	public TipoDocumentoDaoImpl(){
		super(ClpdTipoDocumento.class);
	}

	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}

	public ClpdTipoDocumento obtenerTipoDocumento(Long id) {
		
		ClpdTipoDocumento tipoDocumento = get(id);		
		return tipoDocumento;

	}

	public List<ClpdTipoDocumento> obtenerTipoDocumentos() {
		Criteria criteria = DetachedCriteria.forClass(ClpdTipoDocumento.class)
		.getExecutableCriteria(getSessionFactory().getCurrentSession());

		criteria.setMaxResults(CLPConstantes.MAXIMO_RESULTADO_INICIAL);
		criteria.add(Restrictions.eq("stTipoDocumento", Boolean.TRUE));
		criteria.addOrder(Order.desc("id"));
		
		List<ClpdTipoDocumento> lista = criteria.list(); 
		return lista;
	}
	
	
	
	

}
